package com.saihai.jiankang.ufDjhfbz.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.saihai.jiankang.ufDjhfbz.mapper.UfDjhfbzMapper;
import com.saihai.jiankang.ufDjhfbz.domain.UfDjhfbz;
import com.saihai.jiankang.ufDjhfbz.service.IUfDjhfbzService;

/**
 * SD标准Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-24
 */
@Service
public class UfDjhfbzServiceImpl implements IUfDjhfbzService {
    @Autowired
    private UfDjhfbzMapper ufDjhfbzMapper;

    /**
     * 查询SD标准
     *
     * @param id SD标准主键
     * @return SD标准
     */
    @Override
    public UfDjhfbz selectUfDjhfbzById(Long id) {
        return ufDjhfbzMapper.selectUfDjhfbzById(id);
    }

    /**
     * 查询SD标准列表
     *
     * @param ufDjhfbz SD标准
     * @return SD标准
     */
    @Override
    public List<UfDjhfbz> selectUfDjhfbzList(UfDjhfbz ufDjhfbz) {
        return ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
    }

    /**
     * 新增SD标准
     *
     * @param ufDjhfbz SD标准
     * @return 结果
     */
    @Override
    public int insertUfDjhfbz(UfDjhfbz ufDjhfbz) {
        return ufDjhfbzMapper.insertUfDjhfbz(ufDjhfbz);
    }

    /**
     * 修改SD标准
     *
     * @param ufDjhfbz SD标准
     * @return 结果
     */
    @Override
    public int updateUfDjhfbz(UfDjhfbz ufDjhfbz) {
        return ufDjhfbzMapper.updateUfDjhfbz(ufDjhfbz);
    }

    /**
     * 批量删除SD标准
     *
     * @param ids 需要删除的SD标准主键
     * @return 结果
     */
    @Override
    public int deleteUfDjhfbzByIds(Long[] ids) {
        return ufDjhfbzMapper.deleteUfDjhfbzByIds(ids);
    }

    /**
     * 删除SD标准信息
     *
     * @param id SD标准主键
     * @return 结果
     */
    @Override
    public int deleteUfDjhfbzById(Long id) {
        return ufDjhfbzMapper.deleteUfDjhfbzById(id);
    }

    @Override
    public int yzSg(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setXb(xb);
        ufDjhfbz.setTjlm("sys_sg");
        ufDjhfbz.setNl(nl);
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd5())) > 0) {
                return 0;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd4())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd5())) <= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd2())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd4())) <= 0) {
                return 2;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd2())) <= 0) {
                return 3;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) < 0) {
                return 4;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public int yzTz(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setXb(xb);
        ufDjhfbz.setTjlm("sys_tz");
        ufDjhfbz.setNl(nl);
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd5())) > 0) {
                return 0;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd4())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd5())) <= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd2())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd4())) <= 0) {
                return 2;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd2())) <= 0) {
                return 3;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) < 0) {
                return 4;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public int yzFhl(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setXb(xb);
        ufDjhfbz.setTjlm("sys_fhl");
        ufDjhfbz.setNl(nl);
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd3())) > 0) {
                return 0;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd2())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd3())) <= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd2())) <= 0) {
                return 2;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) < 0) {
                return 3;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public int yzSzy(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setTjlm("sys_szy");
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd4())) >= 0 && sg.compareTo(new BigDecimal(list.get(0).getSd5())) < 0) {
                return 0;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public int yzSsy(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setTjlm("sys_ssy");
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd4())) >= 0 && sg.compareTo(new BigDecimal(list.get(0).getSd5())) < 0) {
                return 0;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public int yzSl(BigDecimal sg, Long xb, Long nl) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setTjlm("sys_lysl");
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        if (list.size() > 0) {
            if (sg.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0) {
                return 0;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd3())) > 0 && sg.compareTo(new BigDecimal(list.get(0).getSd4())) <= 0) {
                return 1;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd2())) >= 0 && sg.compareTo(new BigDecimal(list.get(0).getSd3())) <= 0) {
                return 2;
            } else if (sg.compareTo(new BigDecimal(list.get(0).getSd1())) <= 0) {
                return 3;
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }

    @Override
    public Map<String,Long> yzYsl(BigDecimal zy, BigDecimal zyqj, BigDecimal yy, BigDecimal yyqj, BigDecimal zyzj,BigDecimal yyzj) {
        UfDjhfbz ufDjhfbz = new UfDjhfbz();
        ufDjhfbz.setTjlm("sys_lysl");
        List<UfDjhfbz> list = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        ufDjhfbz.setTjlm("sys_se");
        List<UfDjhfbz> list1 = ufDjhfbzMapper.selectUfDjhfbzList(ufDjhfbz);
        BigDecimal zyse = zyzj.multiply(new BigDecimal("0.5"));
        zyse = zyse.add(zyqj);

        BigDecimal yyse = yyzj.multiply(new BigDecimal("0.5"));
        yyse = yyse.add(yyqj);
        Long zyNum;
        Long yyNum;
        if (zy.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0 && zyse.compareTo(new BigDecimal(list1.get(0).getSd3())) >= 0
        && zyse.compareTo(new BigDecimal(list1.get(0).getSd4())) < 0
        ) {
             zyNum = 1l;
        } else if (zy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && zyse.compareTo(new BigDecimal(list1.get(0).getSd3())) < 0
                && zyse.compareTo(new BigDecimal(list1.get(0).getSd2())) >= 0
        ) {
            zyNum= 2l;
        } else if (zy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && zyse.compareTo(new BigDecimal(list1.get(0).getSd2())) < 0
        &&  zyse.compareTo(new BigDecimal(list1.get(0).getSd1())) >= 0
        ) {
            zyNum= 3l;
        } else if (zy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && zyse.compareTo(new BigDecimal(list1.get(0).getSd1())) < 0) {
            zyNum= 4l;
        }else if (zy.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0 && zyse.compareTo(new BigDecimal(list1.get(0).getSd4())) >= 0) {
            zyNum= 5l;
        }else {
            zyNum = -1l;
        }
        if (zyqj.compareTo(new BigDecimal("999")) == 0) {
            zyNum = 6l;
        }

        if (yy.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0 && yyse.compareTo(new BigDecimal(list1.get(0).getSd3())) >= 0
                && yyse.compareTo(new BigDecimal(list1.get(0).getSd4())) < 0
        ) {
            yyNum = 1l;
        } else if (yy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && yyse.compareTo(new BigDecimal(list1.get(0).getSd3())) < 0
                && yyse.compareTo(new BigDecimal(list1.get(0).getSd2())) >= 0
        ) {
            yyNum= 2l;
        } else if (yy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && yyse.compareTo(new BigDecimal(list1.get(0).getSd2())) < 0
                &&  yyse.compareTo(new BigDecimal(list1.get(0).getSd1())) >= 0
        ) {
            yyNum= 3l;
        } else if (yy.compareTo(new BigDecimal(list.get(0).getSd5())) < 0 && yyse.compareTo(new BigDecimal(list1.get(0).getSd1())) < 0) {
            yyNum= 4l;
        }else if (yy.compareTo(new BigDecimal(list.get(0).getSd5())) >= 0 && yyse.compareTo(new BigDecimal(list1.get(0).getSd4())) >= 0) {
            yyNum= 5l;
        }else {
            yyNum = -1l;
        }
        if (yyqj.compareTo(new BigDecimal("999")) == 0) {
            yyNum = 6l;
        }
        Map<String,Long> map = new HashMap<>();
        map.put("zy",zyNum);
        map.put("yy",yyNum);
        return map;
    }


}
